<template>
	<view>
		<fa-navbar :safeAreaInsetTop="true" :title="title" ref="navbar"></fa-navbar>
		<view class="content">
			<view class="message">
				<view class="item" v-for="(item,index) in messageList" :key="index" :index="index" @click="handleRead(item)">
					<view class="msg-title">
						<view class="msg-tips">
							<u-icon name="http://ob.tenant.com//uploads/20241118/28faa75e0d5df97ceb26a9d1647965b6.png"
								size="80"></u-icon>
							<text class="">{{item.title}}</text>
						</view>
						<view class="msg-data">
							<text>{{item.createtime_text}}</text>
						</view>
					</view>
					<view class="msg-content">
						<text>{{item.content}}</text>
					</view>
				</view>
			</view>
			<!-- 加载更多 -->
			<view class="u-p-b-30" v-if="messageList.length">
				<u-loadmore bg-color="#f4f6f8" fontSize="28" bgColor="#ffffff" :line="true"
					:status="has_more ? status : 'nomore'" />
			</view>
			<!-- 空数据 -->
			<view class="fa-empty" v-if="!messageList.length">
				<u-empty textSize="28"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '消息列表',
				Form:{
					page:1,
					page_size:10,
				},
				messageList:[],
				status:'loadmore',
				is_show:false,
				has_more:false
			};
		},
		
		onLoad() {
			this.getMessageList()
		},
		onReachBottom() {
			if (this.has_more) {
				this.status = 'loading';
				this.Form.page++;
				this.getMessageList();
			}
		},
		methods:{
			handleRead(item){
				console.log(item)
				this.$api.readMessage({id:item.id}).then((res)=>{
					if(res.code){
						
					}
				})
			},
			getMessageList(){
				this.$api.messageList({params:this.Form}).then((res)=>{
					if (res.code) {
						if (this.Form.page === 1) {
							this.list = [];
						}
						let pageList = res.data;
						this.has_more = pageList.current_page < pageList.last_page;
						this.messageList = [...this.messageList, ...pageList.data];
						this.is_show = true;
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.content {
		margin-top: 108rpx;
		.message {
			padding: 20rpx;

			.item {
				border-radius: 10rpx;
				-moz-box-shadow: 10px 10px 5px #888888;
				/* 老的 Firefox */
				box-shadow: 10px 10px 5px #888888;
				padding: 20rpx;
				border: 1rpx solid #cfcfcf;
				margin-bottom: 40rpx;
				.msg-title {
					display: flex;
					align-items: center;
					justify-content:space-between;
					.msg-tips{
						display: flex;
						align-items: center;
						text{
							font-size: 36rpx;
							font-weight: 600;
							padding: 0 20rpx;
						}
					}
					.msg-data{
						color: #333333;
					}
				}
				.msg-content{
					padding: 20rpx 0;
					text{
						font-size: 26rpx;
						color: #333333;
					}
				}
			}
		}
	}
</style>